package com.dzt.androidframework.database.javabean;

import android.text.TextUtils;

import com.google.common.base.Objects;
import java.util.UUID;

/**
 * Created by M02323 on 2017/6/10.
 */

public class Task {
	private final String id;
	private final String title;
	private final String description;
	private final boolean isCompleted;

	public Task(String title, String description) {
		this(title, description, UUID.randomUUID().toString(), false);
	}

	public Task(String title, String description, String id) {
		this(title, description, id, false);
	}

	public Task(String title, String description, boolean completed) {
		this(title, description, UUID.randomUUID().toString(), completed);
	}

	public Task(String title, String description,
				String id, boolean completed) {
		this.id = id;
		this.title = title;
		this.description = description;
		isCompleted = completed;
	}

	public String getId() {
		return id;
	}

	public String getTitle() {
		return title;
	}

	public String getTitleForList() {
		if (!TextUtils.isEmpty(title)) {
			return title;
		} else {
			return description;
		}
	}

	public String getDescription() {
		return description;
	}

	public boolean isCompleted() {
		return isCompleted;
	}

	public boolean isActive() {
		return !isCompleted;
	}

	public boolean isEmpty() {
		return TextUtils.isEmpty(title) &&
				TextUtils.isEmpty(description);
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		Task task = (Task) o;
		return Objects.equal(id, task.id) &&
				Objects.equal(title, task.title) &&
				Objects.equal(description, task.description);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(id, title, description);
	}

	@Override
	public String toString() {
		return "Task{" +
				"id='" + id + '\'' +
				", title='" + title + '\'' +
				", description='" + description + '\'' +
				", isCompleted=" + isCompleted +
				'}';
	}
}
